﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using TruckWatch.Cloud.Models;
//using System.Data;

//namespace TruckWatch.Cloud.DAL
//{
//    class TripDAL
//    {
//        public static void AddTrip(Trip trip)
//        {
//            ParamBuilder pb = new ParamBuilder();
//            pb.AddParam(    SqlDbType.Int, "@DriverId",trip.Driver.Id);
//            pb.AddParam(SqlDbType.Int, "@OriginLocationId", trip.Origination.Id);
//            pb.AddParam(SqlDbType.Int, "@DestinationLocationId", trip.Destination.Id);
//            pb.AddParam(SqlDbType.DateTime, "@ScheduledDeparture", trip.ScheduledDeparture);
//            pb.AddParam(SqlDbType.DateTime, "@ScheduledArrival", trip.ScheduledArrival);

//            string sql = @"
//INSERT INTO [TruckWatch].[dbo].[Trip]
//           ([DriverId]
//           ,[OriginLocationId]
//           ,[DestinationLocationId]
//           ,[ScheduledDeparture]
//           ,[ScheduledArrival])
//     VALUES
//           (@DriverId
//           ,@OriginLocationId
//           ,@DestinationLocationId
//           ,@ScheduledDeparture
//           ,@ScheduledArrival)
//";

//            DataGeneral.ExecuteNonQuery(sql, pb.Parameters);
//        }

//        public static List<Trip> GetTripsByDriverId(int driverid)
//        {
//            ParamBuilder pb = new ParamBuilder();
//            pb.AddParam(SqlDbType.Int, "@DriverId", driverid);

//            string sql = @"
//select
//	Id,[DriverId],[OriginLocationId],[DestinationLocationId],[ScheduledDeparture],[ScheduledArrival]
//from
//	Trip
//where
//	DriverId = @DriverId";

//            DataTable dt = DataGeneral.GetDataTable(sql, pb.Parameters);

//            List<Trip> trips = new List<Trip>();
//            foreach (DataRow row in dt.Rows)
//            {
//                Trip trip = new Trip();
//                trip.Id = (int)row["Id"];
//                trip.Driver = new Driver();
//                trip.Driver.Id = (int)row["DriverId"];
//                trip.Origination = new Location();
//                trip.Origination.Id = (int)row["OriginLocationId"];
//                trip.Destination = new Location();
//                trip.Destination.Id = (int)row["DestinationLocationId"];
//                trip.ScheduledDeparture = (DateTime)row["ScheduledDeparture"];
//                trip.ScheduledArrival = (DateTime)row["ScheduledArrival"];

//                trips.Add(trip);
//            }

//            return trips;
//        }

//    }
//}
